package top.chmin.project.cloud.sys.config.info;
import cn.hutool.core.bean.BeanUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.chmin.project.cloud.common.Page;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import top.chmin.project.cloud.sys.dict.data.DictData;
import top.chmin.project.cloud.sys.dict.data.DictDataCondition;



/**
 * chmin
 * 2024-01-25 14:19:00
 * cloud-code
 */
@Service
@Transactional
public class ConfigInfoService {

    @Resource
    ConfigInfoPlugin plugin;

    public int save(ConfigInfoSaveRest.P p) {
        plugin.checkSave(p);
        ConfigInfo configInfo = BeanUtil.toBean(p, ConfigInfo.class);
        plugin.beforeSave(configInfo);
        int result = configInfo.forInsert().execute();
        plugin.afterSave(p, configInfo, result);
        return result;
    }

    public ConfigInfoSelectRest.R select(ConfigInfoSelectRest.P p) {
        plugin.checkSelect(p);
        ConfigInfoCondition c = ConfigInfoCondition.forSelect().id().eq(p.getId());
        plugin.beforeSelect(p, c);
        ConfigInfoSelectRest.R r = c.selectFirst(ConfigInfoSelectRest.R.class);
        plugin.afterSelect(p, r);
        return r;
    }

    public int update(ConfigInfoUpdateRest.P p) {
        plugin.checkUpdate(p);
        ConfigInfo configInfo = BeanUtil.toBean(p, ConfigInfo.class);
        plugin.beforeUpdate(configInfo);
        int result = configInfo.forUpdate().id().eq().execute();
        plugin.afterUpdate(p, configInfo, result);
        return result;
    }

    public int delete(ConfigInfoDeleteRest.P p) {
        plugin.checkDelete(p);
        ConfigInfo configInfo = BeanUtil.toBean(p, ConfigInfo.class);
        plugin.beforeDelete(configInfo);
        int result = configInfo.forDelete().id().eq().execute();
        plugin.afterDelete(p, configInfo, result);
        return result;
    }

    public Page<ConfigInfoPageRest.R> page(ConfigInfoPageRest.P p) {
        plugin.checkPage(p);
        ConfigInfoCondition c = ConfigInfoCondition.forSelect();
        c = p.isDesc() ? c.id().desc() : c.id().asc();
        plugin.beforePage(p, c);
        Page<ConfigInfoPageRest.R> r = c.selectPage(ConfigInfoPageRest.R.class);
        /*###########auto#start###########*/
        /*###########auto##end############*/
        /* append $serviceRelateAppender$ */
        /*###########auto#start###########*/
        /*###########auto##end############*/
        /* append $serviceDictAppender$ */
        plugin.afterPage(p, r);
        return r;
    }

    /*###########auto#start###########*/
    public List<ConfigInfoSelectConfigCodeOptionRest.R> selectConfigCodeOption(ConfigInfoSelectConfigCodeOptionRest.P p) {
        plugin.checkSelectConfigCodeOption(p);
        ConfigInfoCondition c = ConfigInfoCondition.forSelect();
        c.limit(100);
        plugin.beforeSelectConfigCodeOption(p, c);
        List<ConfigInfoSelectConfigCodeOptionRest.R> r = c.selectList(ConfigInfoSelectConfigCodeOptionRest.R.class);
        plugin.afterSelectConfigCodeOption(p, r);
        return r;
    }

    /*###########auto##end############*/
    /* append $serviceSelectOptionMethodAppender$ */
}
